package cn.edu.bit.lixin.blog.biz;

import java.util.List;

import cn.edu.bit.lixin.blog.dao.UserDAO;
import cn.edu.bit.lixin.blog.entity.User;

public class UserManager {
	private UserDAO dao;

	public UserDAO getDao() {
		return dao;
	}

	public void setDao(UserDAO dao) {
		this.dao = dao;
	}
	
	public User getSpecificUser(int userId){
		User user = (User)dao.findById(User.class, userId);
		return user;
	}
	
	/**
	 * 判断输入的验证码是否正确
	 * @param verifyCodeInput
	 * @param verifyCodeSession
	 * @return
	 */
	public boolean judgeVerifyCode(String verifyCodeInput, String verifyCodeSession){
		if (verifyCodeInput.equalsIgnoreCase(verifyCodeSession)){
			return true;
		}
		return false;
	}
	
	/**
	 * 判断用户登录是否成功
	 * @param username
	 * @param password
	 * @return
	 */
	public User checkLogin(String username, String password){
		List<User> userList = dao.findByName("User", "user", username);
		User user;
		if (userList == null || userList.size() == 0){
			return null;
		}
		user = userList.get(0);
		if (user != null){
			System.out.println("找到用户名");
			if (user.getPassword().equals(password)){
				System.out.println("密码正确");
				return user;
			}
		}
		return null;
	}
	
}
